function Circle(x, y, radius){
	this.x = x;
	this.y = y;
	this.radius = radius;
	this.strokeStyle = 'rgba(255, 253, 208, 0.9)';
	this.fillStyle = 'rgba(147, 197, 114, 0.8)';
}

Circle.prototype = new Shape();

Circle.prototype.collidesWith = function(shape){
	var axes = shape.getAxes(),
		distance;

	if(axes === undefined){ // 判断为圆
		distance = Math.sqrt(Math.pow(shape.x - this.x, 2) + Math.pow(shape.y - this.y, 2));

		return distance < Math.abs(this.radius + shape.radius);
	}else{ // 判断为多边形
		return polygonCollidesWithCircle(shape, this);
	}	
};

Circle.prototype.getAxes = function(){
	return undefined; // 圆有无限条投影
};

Circle.prototype.project = function(axis){
	var scalars = [],
		point = new Point(this.x, this.y),
		dotProduct = new Vector(point).dotProduct(axis);

	scalars.push(dotProduct);
	scalars.push(dotProduct + this.radius);
	scalars.push(dotProduct - this.radius);

	return new Projection(Math.min.apply(Math, scalars), Math.max.apply(Math, scalars));
};

Circle.prototype.move = function(dx, dy){
	this.x += dx;
	this.y += dy;
};

Circle.prototype.createPath = function(context){
	context.beginPath();
	context.arc(this.x, this.y, this.radius, 0, Math.PI*2, false);
};

// 检测多边形与圆之间的碰撞
function getPolygonPointClosestToCircle(polygon, circle){
	var min = 10000,
		length,
		testPoint,
		closestPoint;

	for(var i = 0; i < polygon.points.length; i++){
		testPoint = polygon.points[i];
		length = Math.sqrt(Math.pow(testPoint.x - circle.x, 2) + Math.pow(testPoint.y - circle.y, 2));

		if(length < min){
			min = length;
			closestPoint = testPoint;
		}

	}

	return closestPoint;
}

function polygonCollidesWithCircle(polygon, circle){
	var min = 10000,
		v1, 
		v2,
		edge,
		perpendicular,
		normal,
		axes = polygon.getAxes(),
		closestPoint = getPolygonPointClosestToCircle(polygon, circle);

	v1 = new Vector(new Point(circle.x, circle.y));
	v2 = new Vector(new Point(closestPoint.x, closestPoint.y));
	
	axes.push(v1.subtract(v2).normalize());

	return !polygon.separationOnAxes(axes, circle);
}